﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Data;

namespace SL5.SampleApp
{
	public sealed class MultiBooleanConverter : IMultiValueConverter
	{
		public static readonly MultiBooleanConverter Instance = new MultiBooleanConverter();

		private MultiBooleanConverter()
		{
		}

		public static IMultiValueConverter GetInstance(object value)
		{
			Debug.WriteLine(MethodBase.GetCurrentMethod());
			return Instance;
		}
		
		public static IMultiValueConverter GetInstance(long value)
		{
			Debug.WriteLine(MethodBase.GetCurrentMethod());
			return Instance;
		}
		
		object IMultiValueConverter.Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
		{
			if (values != null)
			{
				IEnumerable<bool> bools = values.OfType<bool>();
				switch (parameter == null ? "All" : parameter.ToString())
				{
					case "All":
						return bools.All(x => x);
					case "None":
						return bools.All(x => !x);
					case "Any":
						return bools.Any(x => x);
				}
			}
			return DependencyProperty.UnsetValue;
		}
		
		object[] IMultiValueConverter.ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
		{
			throw new NotImplementedException();
		}
	}
}